package com.example.nep.controller;


import com.example.nep.base.R;
import com.example.nep.model.GridMember;
import com.example.nep.service.IGridMemberService;
import com.example.nep.util.JwtUtil;
import com.example.nep.vo.UserVO;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author han
 * @since 2024-04-11
 */
@CrossOrigin
@RestController
@RequestMapping("gridMember")
public class GridMemberController {
    @Resource
    private IGridMemberService gridMemberService;
    @GetMapping("login")
    public R login(@RequestParam String gmCode,String password){
        GridMember gm = gridMemberService.login(gmCode, password);
        UserVO userVO=new UserVO();
        userVO.setRole(2);
        userVO.setGmCode(gm.getGmCode());
        String token = JwtUtil.newToken(userVO);
        return R.ok().setResult("token",token).setResult("gm",gm);
    }
    @GetMapping("gmAll")
    public R gmAll(@RequestParam Integer cityId,@RequestParam Integer provinceId){
        List<GridMember> gridMembers = gridMemberService.gmAll(cityId, provinceId);
        return R.ok().setResult("gridMembers",gridMembers);
    }
}
